﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Admin.Common.SqlTool
{
    public class SqlHelper
    {
        /// <summary>
        /// 生成逗号隔开的字符串
        /// </summary>
        /// <param name="fields">字段数组</param>
        /// <returns></returns>
        public static string SqlJoin(string[] fields)
        {
            string result = string.Empty;
            foreach (var item in fields)
            {
                //result = $"{result}{StringHelper.ToDbField(item)},";
                result = $"{result}{item},";
            }
            return result.TrimEnd(',');
        }

        /// <summary>
        /// 生成@+字段 逗号隔开的字符串
        /// </summary>
        /// <param name="fields">字段数组</param>
        /// <returns></returns>
        public static string SqlValueJoin(string[] fields)
        {
            string result = string.Empty;
            foreach (var item in fields)
            {
                if (!string.IsNullOrWhiteSpace(item))
                    result = $"{result}@{item},";
            }
            return result.TrimEnd(',');
        }

        /// <summary>
        /// 生成修改的set字段
        /// </summary>
        /// <param name="fields">要修改的字段</param>
        /// <returns></returns>
        public static string SqlSetJoin(string[] fields)
        {
            string result = string.Empty;
            foreach (var item in fields)
            {
                if (!string.IsNullOrWhiteSpace(item))
                    result = $"{result}{item}=@{item},";
            }
            return result.TrimEnd(',');
        }


    }
}
